package com.solute.utils.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class SSOInterceptor extends HandlerInterceptorAdapter {
	
	private static final Logger logger = LoggerFactory.getLogger(SSOInterceptor.class); 

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		logger.debug("main URI SSO Check Started");
		HttpSession session = request.getSession();
		if(session.getAttribute("user") == null) {
			response.sendRedirect("/login");
			logger.debug("SSO Check Denied");
			return false;
		} else {
			request.setAttribute("isLogined", true);
		}
		logger.debug("main URI SSO Check Finished");
		
		return super.preHandle(request, response, handler);
	}

}
